﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business.Manager;
using Business.IManager;
using Entity;

namespace OnlinePayment.Admin
{
    public partial class AddOperatorOrAdmin : System.Web.UI.Page
    {
        IDepartmentManager departmentManage = new DepartmentManager();
        IAccountManager accountManager = new AccountManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            //权限检查
            if (!IsPostBack)
            {
                bindDepartment();
                bindRoleName();
            }
        }

        private void bindDepartment()
        {
            depList.DataSource = departmentManage.getDepartment();
            depList.DataTextField = "depName";
            depList.DataValueField = "deptId";
            depList.DataBind();
        }

        private void bindRoleName()
        {
            roleList.DataSource = accountManager.getAuthorityDS();
            roleList.DataTextField = "roleName";
            roleList.DataValueField = "roleId";
            roleList.DataBind();
        }

        protected void btn_OperatorStudent_Click(object sender, EventArgs e)
        {
            Operator oper=new Operator();
            oper.OperatorName = txtOperName.Text;
            oper.LoginId = txtLoginId.Text;
            oper.LoginPwd = txtPassword.Text;
            oper.DeptId = Convert.ToInt32(depList.SelectedItem.Value);
            oper.RoleId = Convert.ToInt32(roleList.SelectedItem.Value);
            if(accountManager.addOperator(oper)){
                Response.Write( " <script language=javascript> alert( '添加成功 '); </script>");
            }else{
                Response.Write(" <script language=javascript> alert( '添加失败 '); </script>");
            }
        }


    }
}